<template>
  <!--乡村议事会-->
  <div class="mod-bus__busnotice">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <!--      <el-form-item>-->
      <!--        <el-input v-model="state.dataForm.title" placeholder="标题" clearable></el-input>-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('clc:clcdiscussion:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t("add")
          }}{{ moduleName }}
        </el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('clc:clcdiscussion:delete')" type="danger" @click="state.deleteHandle()">{{
            $t("deleteBatch")
          }}{{ moduleName }}
        </el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
              @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="remark" label="名称" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="address" label="地点" header-align="center" align="center"></el-table-column>
      <el-table-column prop="activityTime" label="时间" header-align="center" align="center">
      </el-table-column>
      <el-table-column prop="recruit" label="人数" header-align="center" align="center"></el-table-column>
      <el-table-column prop="participate" label="参与对象" header-align="center" align="center"></el-table-column>
      <el-table-column prop="phone" label="联系电话" header-align="center" align="center"></el-table-column>
      <el-table-column prop="image" label="图片" header-align="center" align="center">
        <template v-slot="scope">
          <el-image
            v-if="scope.row.url"
            :src=" 'https://' + scope.row.url"
            style="height: 50px;width: 50px;"
            :preview-src-list="['https://' +scope.row.url]"
            :preview-teleported="true"
            :initial-index="0"
            fit="cover"
          ></el-image>
          <div v-else>无</div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('clc:clcdiscussion:update')" type="primary" link
                     @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}
          </el-button>
          <el-button v-if="state.hasPermission('clc:clcdiscussion:delete')" type="primary" link
                     @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                   :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                   @size-change="state.pageSizeChangeHandle"
                   @current-change="state.pageCurrentChangeHandle"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import {IObject} from "@/types/interface";
import baseService from "@/service/baseService";
import {reactive, ref, toRefs} from "vue";
import AddOrUpdate from "./village-council-add.vue";

//子组件接收父组件传递过来的值
const props = defineProps(["moduleCode", "moduleName"]);
const moduleCode = ref(props.moduleCode);
const moduleName = ref(props.moduleName);

const view = reactive({
  getDataListURL: "/clc/clcdiscussion/page",
  getDataListIsPage: true,
  exportURL: "/clc/clcdiscussion/export",
  deleteURL: "/clc/clcdiscussion",
  deleteIsBatch: true,
  dataForm: {
    title: ""
  }
});

const state = reactive({...useView(view), ...toRefs(view)});

const addKey = ref(0);
const addOrUpdateRef = ref();

const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};

// 是否发布
const publishRow = (row: IObject) => {
  row.isPublish = row.isPublish ? 0 : 1
  baseService.put("/clc/clcdiscussion/", row).then((res) => {
    state.getDataList();
  });
};

// 是否置顶
const topRow = (row: IObject) => {
  row.isTopped = row.isTopped ? 0 : 1
  baseService.put("/clc/clcdiscussion/", row).then((res) => {
    state.getDataList();
  });
};

</script>
